import {
  Component,
  Injector,
  ViewEncapsulation,
  ViewChild,
  ElementRef,
} from "@angular/core";
import { AppComponentBase } from "@shared/common/app-component-base";
import {
  PipelineListDto,
  ComboboxItemDto,
} from "@shared/service-proxies/service-proxies";
import { PipelineNodeServiceProxy } from "@shared/service-proxies/service-proxies";
import { finalize } from "rxjs/operators";
import { appModuleAnimation } from "@shared/animations/routerTransition";

@Component({
  selector: "rw22",
  templateUrl: "./rw22.component.html",
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()],
})
export class RW22ModalComponent extends AppComponentBase {
  saving = false;

  pipe: PipelineListDto = new PipelineListDto();

  youxianji = 1;

  shitai = false;

  constructor(
    injector: Injector,
    private _taskServiceProxy: PipelineNodeServiceProxy
  ) {
    super(injector);
  }

  load(pipe: PipelineListDto): void {
    this.pipe = pipe;

    this._taskServiceProxy.getPriority(pipe.id).subscribe((result) => {
      this.youxianji = result;
    });

    this._taskServiceProxy.getIsShiTai(pipe.id).subscribe((result) => {
      this.shitai = result;
    });
  }

  save(): void {
    this.saving = true;

    this._taskServiceProxy
      .setPriorityAndIsShiTai(this.pipe.id, this.youxianji, this.shitai)
      .pipe(
        finalize(() => {
          this.saving = false;
        })
      )
      .subscribe((result) => {
        // this._taskServiceProxy
        //   .setCurrentActRemark(this.pipe.id, this.shitai)
        //   .subscribe(result => {
        this.notify.success("记录数据成功");
        // });
      });
  }
}
